<?php

class Light_View_Helper_FlashMessage extends Light_View_Helper_Abstract
{
    public function flashMessage()
    {
        return $this;
    }

    public function setMessage($message = 'Data saved', $type = 'success')
    {
        $_SESSION[LIGHT_SESSION_NAME]['message'] = array(
            'message' => $message,
            'type'    => $type
        );

        return $this;
    }

    public function getMessage()
    {
        $buff = '';

        if (isset($_SESSION[LIGHT_SESSION_NAME]['message'])) {
            $buff = '<div id="message" class="' . $_SESSION[LIGHT_SESSION_NAME]['message']['type'] . '">' . $this->view->translate($_SESSION[LIGHT_SESSION_NAME]['message']['message']) . '</div>';
            unset($_SESSION[LIGHT_SESSION_NAME]['message']);
        }

        return $buff;
    }
}